package com.neusoft.elmboot.controller;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.CreditTransaction;
import com.neusoft.elmboot.service.CreditTransactionService;

@RestController
@RequestMapping("/CreditTransaction")
public class CreditTransactionController {

	@Autowired
	private CreditTransactionService creditTransactionService ;
	
	//获得积分
	@PutMapping("/earnCredits")
	public int EarnCredits(@RequestBody CreditTransactionVo creditTransactionVo) {
		CreditTransaction creditTransaction = creditTransactionVo.CreditTransactionVo2CreditTransaction();
		return creditTransactionService.EarnCredits(creditTransaction);
	}
	
	//返回总可用积分
	@GetMapping("/inquireCredits")
	public BigDecimal InquireCredits(@RequestBody CreditTransactionVo creditTransactionVo) {
		return creditTransactionService.AllCredits(creditTransactionVo.getUserId());
	}
	
	// 返回总积分明细
	@GetMapping("/inquireCreditTransaction")
	public List<CreditTransaction> InquireCreditTransaction(@RequestBody CreditTransactionVo creditTransactionVo) {
		return creditTransactionService.CreditTransaction(creditTransactionVo.getUserId());
	}
	
	// 返回总获得积分明细
	@GetMapping("/inquireEarnCreditTransaction")
	public List<CreditTransaction> InquireEarnCreditTransaction(@RequestBody CreditTransactionVo creditTransactionVo) {
		return creditTransactionService.EarnCreditTransaction(creditTransactionVo.getUserId());
	}

	// 返回总使用积分明细
	@GetMapping("/inquireUsedCreditTransaction")
	public List<CreditTransaction> InquireUsedCreditTransaction(@RequestBody CreditTransactionVo creditTransactionVo) {
		return creditTransactionService.UsedCreditTransaction(creditTransactionVo.getUserId());
	}
	
	//使用积分
	@PutMapping("/useCredits")
	public int UseCredits(@RequestBody CreditTransactionVo creditTransactionVo) {
		CreditTransaction creditTransaction = creditTransactionVo.CreditTransactionVo2CreditTransaction();
		return creditTransactionService.UseCredits(creditTransaction);
	}
	
	
}

class CreditTransactionVo {
	private String userId;
	private String channalId;
	private String eventId;
	private BigDecimal credit;
	
	public CreditTransaction CreditTransactionVo2CreditTransaction() {
		CreditTransaction creditTransaction = new CreditTransaction();
		creditTransaction.setUserId(this.userId);
		creditTransaction.setChannalId(this.channalId);
		creditTransaction.setEventId(this.eventId);
		creditTransaction.setCredit(this.credit);
		return creditTransaction;
	}
	
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getChannalId() {
		return channalId;
	}
	public void setChannalId(String channalId) {
		this.channalId = channalId;
	}
	public String getEventId() {
		return eventId;
	}
	public void setEventId(String eventId) {
		this.eventId = eventId;
	}
	public BigDecimal getCredit() {
		return credit;
	}
	public void setCredit(BigDecimal credit) {
		this.credit = credit;
	}
	
}